package com.bll;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bll.imple.userAction.AddUserAction;
import com.bll.imple.userAction.DeleteUserAction;
import com.bll.imple.userAction.HLoginAction;
import com.bll.imple.userAction.ShowAllUserAction;
import com.bll.imple.userAction.ShowUserAction;
import com.bll.imple.userAction.UpdateUserAction;
import com.bll.imple.userAction.UpdateUserDoAction;
import com.bll.imple.userAction.UserLoginAction;
public class UserServlet extends HttpServlet {
	private Map map=new HashMap();

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		//System.out.println("idsss:"+request.getParameter("username"));
		
		PrintWriter out=response.getWriter();//�������
		
		//�õ�·��
		String path=request.getServletPath();
		out.println("path:"+path);
		//��ȡ·��
		String acname = path.substring(path.lastIndexOf("/")+1,path.length()-5);
		System.out.println("acname:"+acname);
		
		Action action=(Action)map.get(acname);
		//out.println("action:"+action);
		String desPath=action.execute(request,response);
		System.out.println("desPath:"+desPath);
		System.out.println("111111");
		if(!desPath.equals("false")){
			request.getRequestDispatcher(desPath).forward(request, response);
		}
		
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	    doGet(request,response);
	}


	public void init() throws ServletException {
	
		map.put("AddUser",new AddUserAction());
		map.put("UpdateUser", new UpdateUserAction());
		map.put("UpdateUserDo", new UpdateUserDoAction());
		map.put("DeleteUser", new DeleteUserAction());
		map.put("ShowAllUser", new ShowAllUserAction());
		map.put("ShowUser", new ShowUserAction());
		map.put("login", new HLoginAction());
	}

}
